
import Manage.LogRecorderAndAnalyzer;
import Manage.PermissionManager;
import Manage.SystemHealthMonitor;

import java.util.Scanner;

public class SystemManagement extends SystemManager {
private Scanner scanner;
private PermissionManager permissionManager = new PermissionManager();
private LogRecorderAndAnalyzer logRecorderAndAnalyzer = new LogRecorderAndAnalyzer();
private SystemHealthMonitor systemHealthMonitor = new SystemHealthMonitor();

public SystemManagement(Scanner scanner) {
    super(scanner);
    this.scanner = scanner;
}
public void manage() {
    while (true) {
        System.out.println("\n=== 系统管理 ===");
        System.out.println("1. 用户权限管理");
        System.out.println("2. 作业日志记录与分析");
        System.out.println("3. 系统健康监测");
        System.out.println("4. 返回主菜单");

        int choice = getUserChoice(1, 4, "请输入选择(1-4): ");

        if (choice == 4) {
            return;
        }

        switch (choice) {
            case 1:
                manageUserPermissions();
                break;
            case 2:
                recordAndAnalyzeLogs();
                break;
            case 3:
                monitorSystemHealth();
                break;
        }
    }
}

private void manageUserPermissions() {
            while (true) {
                System.out.println("\n=== 用户权限管理 ===");
                System.out.println("1. 添加用户");
                System.out.println("2. 删除用户");
                System.out.println("3. 分配权限");
                System.out.println("4. 查看用户权限");
                System.out.println("5. 返回");

                int choice = getUserChoice(1, 5, "请输入选择(1-5): ");

                if (choice == 5) {
                    return;
                }
                switch (choice) {
                    case 1:
                        System.out.print("请输入用户名: ");
                        String username = scanner.nextLine();
                        System.out.print("请输入权限（用逗号分隔）: ");
                        String[] permissions = scanner.nextLine().split(",");
                        permissionManager.addUser(username, permissions);
                        break;
                    case 2:
                        System.out.print("请输入要删除的用户名: ");
                        username = scanner.nextLine();
                        permissionManager.removeUser(username);
                        break;
                    case 3:
                        System.out.print("请输入用户名: ");
                        username = scanner.nextLine();
                        System.out.print("请输入新的权限（用逗号分隔）: ");
                        permissions = scanner.nextLine().split(",");
                        permissionManager.assignPermissions(username, permissions);
                        break;
                    case 4:
                        System.out.print("请输入要查看权限的用户名: ");
                        username = scanner.nextLine();
                        permissionManager.viewPermissions(username);
                        break;
                }
            }
}

private void recordAndAnalyzeLogs() {
    while (true) {
        System.out.println("\n=== 作业日志记录与分析 ===");
        System.out.println("1. 记录日志");
        System.out.println("2. 分析日志");
        System.out.println("3. 返回");

        int choice = getUserChoice(1, 3, "请输入选择(1-3): ");

        if (choice == 3) {
            return;
        }

        switch (choice) {
            case 1:
                System.out.print("请输入日志内容: ");
                String message = scanner.nextLine();
                logRecorderAndAnalyzer.recordLog(message);
                break;
            case 2:
                logRecorderAndAnalyzer.analyzeLogs();
                break;
        }
    }
}

private void monitorSystemHealth() {
    systemHealthMonitor.checkSystemHealth();
}
}